package org.zhengquan.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
import org.zhengquan.common.JsonData;
import org.zhengquan.dto.AclModuleLevelDto;
import org.zhengquan.service.SysAclModuleService;
import org.zhengquan.service.SysTreeService;
import org.zhengquan.vo.AclModuleVO;

import java.util.List;

/**
 * @author zhengquan
 * @date 2017/11/2
 */
@Controller
@RequestMapping("/sys/aclModule/")
public class SysAclModuleController {

    @Autowired
    private SysAclModuleService sysAclModuleService;

    @Autowired
    private SysTreeService sysTreeService;

    @RequestMapping("acl.page")
    public ModelAndView page() {
        return new ModelAndView("acl");
    }

    @RequestMapping("save.json")
    @ResponseBody
    public JsonData save(AclModuleVO aclModuleVO) {
        sysAclModuleService.save(aclModuleVO);
        return JsonData.success();
    }

    @RequestMapping("tree.json")
    @ResponseBody
    public JsonData tree() {
        List<AclModuleLevelDto> aclModuleLevelDtoList = sysTreeService.aclModuleTree();
        return JsonData.success(aclModuleLevelDtoList);
    }

    @RequestMapping("update.json")
    @ResponseBody
    public JsonData update(AclModuleVO aclModuleVO) {
        sysAclModuleService.update(aclModuleVO);
        return JsonData.success();
    }

    @RequestMapping("delete.json")
    @ResponseBody
    public JsonData delete(@RequestParam("id") Integer id){
        sysAclModuleService.delete(id);
        return JsonData.success();
    }
}
